package code.main.modle.config
{
	import code.phpnet.GlobalConfig;
	
	import com.yy.dataStructure.HashMap;
	import com.yy.tools.arry.ArrayTools;
	import com.yy.tools.load.LoadSwfParamInfo;
	import com.yy.tools.load.LoaderSWF;
	
	import flash.display.Loader;

	/**
	 *配置文件数据 
	 * @author YY
	 * 
	 */
	public class ConfigData
	{
		private var _commandAddr:HashMap;//web命令地址
		private var _swfInfo:HashMap;//swf信息
		private var _chatServer:String = "";//聊天服务器
		private var _chatPort:int = 0;//聊天端口
		private var _dnServer:String = "";//斗牛socketfu服务器
		private var _dnPort:int = 0;//斗牛服务器端口
		private var _img:String;//资源地址
		public var preLoadKeys:Array;//预加载资源键值
		public function ConfigData()
		{
			_commandAddr = new HashMap();
			_swfInfo = new HashMap();
		}
		
		/**
		 *解析配置文件
		 * @param xml
		 * 
		 */
		public function parse(xml:XML):void {
			var len:int;
			var i:int;
			//资源地址
			_img = String(xml.img.@url);
			//聊socket天配置
			_chatServer = String(xml.chat.@server);
			_chatPort = int(xml.chat.@port);
			//斗牛socket配置
			_dnServer = String(xml.socket.@server);
			_dnPort = int(xml.socket.@port);
			//解析预加载swf信息
			preLoadKeys = String(xml.preLoadKeys).split(",");
			ArrayTools.executeFunc(preLoadKeys, xxFunc);
			function xxFunc(obj:Object):int {
				return int(obj);
			}
			//swf 信息
			len = xml.swf.elements("item").length();
			var pram:LoadSwfParamInfo;
			var tempObj:Object;
			for(i=0; i<len; i++) {
				pram = new LoadSwfParamInfo();
				tempObj = xml.swf.item[i];
				pram.address = GlobalConfig.instance.flashurl + String(tempObj.@swfName);
				pram.key = String(tempObj.@key);
				pram.swfSize = int(tempObj.@size)*1024;
				_swfInfo.put(pram.key, pram);
			}
			//解析命令地址
			len = xml.command.elements("item").length();
			for(i=0; i<len; i++) {
				tempObj = xml.command.item[i];
				_commandAddr.put(String(tempObj.@msg), String(tempObj.@server));
			}
		}
		
		/**
		 *活得swf信息 
		 * @param swfKey 的key
		 * @return 
		 * 
		 */
		public function getSwfInofs(keys:Array):Array {
			var i:int;
			var len:int = keys.length;
			var param:LoadSwfParamInfo;
			var arr:Array = [];
			for(i=0; i<len; i++) {
				param = _swfInfo.getValue(keys[i]);
				if(param) {
					arr.push(param);
				}
			}
			return arr;
		}
		
		/**
		 * 获得命令地址
		 * @param commdId 命令号
		 * @return 
		 * 
		 */
		public function getAddr(commdId:String):String {
			return _commandAddr.getValue(commdId);
		}

		public function get img():String
		{
			return _img;
		}

		public function set img(value:String):void
		{
			_img = value;
		}

		public function get dnPort():int
		{
			return _dnPort;
		}

		public function set dnPort(value:int):void
		{
			_dnPort = value;
		}

		public function get dnServer():String
		{
			return _dnServer;
		}

		public function set dnServer(value:String):void
		{
			_dnServer = value;
		}


	}
}